.class public Lorg/microemu/util/MemoryRecordStoreManager;
.super Ljava/lang/Object;
.source "MemoryRecordStoreManager.java"

# interfaces
.implements Lorg/microemu/RecordStoreManager;


# instance fields
.field private recordListener:Lorg/microemu/util/ExtendedRecordListener;

.field private recordStores:Ljava/util/Hashtable;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 37
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 38
    new-instance v0, Ljava/util/Hashtable;

    invoke-direct {v0}, Ljava/util/Hashtable;-><init>()V

    iput-object v0, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    .line 40
    const/4 v0, 0x0

    iput-object v0, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    return-void
.end method


# virtual methods
.method public deleteRecordStore(Ljava/lang/String;)V
    .locals 2
    .parameter "recordStoreName"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreNotFoundException;,
            Ljavax/microedition/rms/RecordStoreException;
        }
    .end annotation

    .prologue
    .line 50
    iget-object v1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v1, p1}, Ljava/util/Hashtable;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lorg/microemu/util/RecordStoreImpl;

    .line 51
    .local v0, recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    if-nez v0, :cond_0

    .line 52
    new-instance v1, Ljavax/microedition/rms/RecordStoreNotFoundException;

    invoke-direct {v1, p1}, Ljavax/microedition/rms/RecordStoreNotFoundException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 54
    :cond_0
    invoke-virtual {v0}, Lorg/microemu/util/RecordStoreImpl;->isOpen()Z

    move-result v1

    if-eqz v1, :cond_1

    .line 55
    new-instance v1, Ljavax/microedition/rms/RecordStoreException;

    invoke-direct {v1}, Ljavax/microedition/rms/RecordStoreException;-><init>()V

    throw v1

    .line 57
    :cond_1
    iget-object v1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v1, p1}, Ljava/util/Hashtable;->remove(Ljava/lang/Object;)Ljava/lang/Object;

    .line 59
    const/16 v1, 0xa

    invoke-virtual {p0, v1, p1}, Lorg/microemu/util/MemoryRecordStoreManager;->fireRecordStoreListener(ILjava/lang/String;)V

    .line 60
    return-void
.end method

.method public deleteStores()V
    .locals 1

    .prologue
    .line 105
    iget-object v0, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    if-eqz v0, :cond_0

    .line 106
    iget-object v0, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v0}, Ljava/util/Hashtable;->clear()V

    .line 107
    :cond_0
    return-void
.end method

.method public fireRecordStoreListener(ILjava/lang/String;)V
    .locals 3
    .parameter "type"
    .parameter "recordStoreName"

    .prologue
    .line 119
    iget-object v0, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    if-eqz v0, :cond_0

    .line 120
    iget-object v0, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v1

    invoke-interface {v0, p1, v1, v2, p2}, Lorg/microemu/util/ExtendedRecordListener;->recordStoreEvent(IJLjava/lang/String;)V

    .line 122
    :cond_0
    return-void
.end method

.method public getName()Ljava/lang/String;
    .locals 1

    .prologue
    .line 46
    const-string v0, "Memory record store"

    return-object v0
.end method

.method public getSizeAvailable(Lorg/microemu/util/RecordStoreImpl;)I
    .locals 2
    .parameter "recordStoreImpl"

    .prologue
    .line 111
    invoke-static {}, Ljava/lang/Runtime;->getRuntime()Ljava/lang/Runtime;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/Runtime;->freeMemory()J

    move-result-wide v0

    long-to-int v0, v0

    return v0
.end method

.method public init()V
    .locals 0

    .prologue
    .line 101
    invoke-virtual {p0}, Lorg/microemu/util/MemoryRecordStoreManager;->deleteStores()V

    .line 102
    return-void
.end method

.method public init(Lorg/microemu/MicroEmulator;)V
    .locals 0
    .parameter "emulator"

    .prologue
    .line 43
    return-void
.end method

.method public listRecordStores()[Ljava/lang/String;
    .locals 4

    .prologue
    .line 83
    const/4 v2, 0x0

    .line 85
    .local v2, result:[Ljava/lang/String;
    const/4 v1, 0x0

    .line 86
    .local v1, i:I
    iget-object v3, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v3}, Ljava/util/Hashtable;->keys()Ljava/util/Enumeration;

    move-result-object v0

    .local v0, e:Ljava/util/Enumeration;
    :goto_0
    invoke-interface {v0}, Ljava/util/Enumeration;->hasMoreElements()Z

    move-result v3

    if-eqz v3, :cond_1

    .line 87
    if-nez v2, :cond_0

    .line 88
    iget-object v3, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v3}, Ljava/util/Hashtable;->size()I

    move-result v3

    new-array v2, v3, [Ljava/lang/String;

    .line 90
    :cond_0
    invoke-interface {v0}, Ljava/util/Enumeration;->nextElement()Ljava/lang/Object;

    move-result-object v3

    check-cast v3, Ljava/lang/String;

    aput-object v3, v2, v1

    .line 91
    add-int/lit8 v1, v1, 0x1

    goto :goto_0

    .line 94
    :cond_1
    return-object v2
.end method

.method public openRecordStore(Ljava/lang/String;Z)Ljavax/microedition/rms/RecordStore;
    .locals 2
    .parameter "recordStoreName"
    .parameter "createIfNecessary"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/rms/RecordStoreNotFoundException;
        }
    .end annotation

    .prologue
    .line 64
    iget-object v1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v1, p1}, Ljava/util/Hashtable;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lorg/microemu/util/RecordStoreImpl;

    .line 65
    .local v0, recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    if-nez v0, :cond_1

    .line 66
    if-nez p2, :cond_0

    .line 67
    new-instance v1, Ljavax/microedition/rms/RecordStoreNotFoundException;

    invoke-direct {v1, p1}, Ljavax/microedition/rms/RecordStoreNotFoundException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 69
    :cond_0
    new-instance v0, Lorg/microemu/util/RecordStoreImpl;

    .end local v0           #recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    invoke-direct {v0, p0, p1}, Lorg/microemu/util/RecordStoreImpl;-><init>(Lorg/microemu/RecordStoreManager;Ljava/lang/String;)V

    .line 70
    .restart local v0       #recordStoreImpl:Lorg/microemu/util/RecordStoreImpl;
    iget-object v1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordStores:Ljava/util/Hashtable;

    invoke-virtual {v1, p1, v0}, Ljava/util/Hashtable;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 72
    :cond_1
    const/4 v1, 0x1

    invoke-virtual {v0, v1}, Lorg/microemu/util/RecordStoreImpl;->setOpen(Z)V

    .line 73
    iget-object v1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    if-eqz v1, :cond_2

    .line 74
    iget-object v1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    invoke-virtual {v0, v1}, Lorg/microemu/util/RecordStoreImpl;->addRecordListener(Ljavax/microedition/rms/RecordListener;)V

    .line 77
    :cond_2
    const/16 v1, 0x8

    invoke-virtual {p0, v1, p1}, Lorg/microemu/util/MemoryRecordStoreManager;->fireRecordStoreListener(ILjava/lang/String;)V

    .line 79
    return-object v0
.end method

.method public saveChanges(Lorg/microemu/util/RecordStoreImpl;)V
    .locals 0
    .parameter "recordStoreImpl"

    .prologue
    .line 98
    return-void
.end method

.method public setRecordListener(Lorg/microemu/util/ExtendedRecordListener;)V
    .locals 0
    .parameter "recordListener"

    .prologue
    .line 115
    iput-object p1, p0, Lorg/microemu/util/MemoryRecordStoreManager;->recordListener:Lorg/microemu/util/ExtendedRecordListener;

    .line 116
    return-void
.end method
